package com.cat.binaryTree;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/flip-equivalent-binary-trees/description/
 * @create 2025/9/11 23:01
 * @since JDK17
 */

public class Solution20 {
    public boolean flipEquiv(TreeNode root1, TreeNode root2) {
        if (root1 == null) {
            return root2 == null;
        }
        if (root2 == null) {
            return root1 == null;
        }
        if (root1.val != root2.val) {
            return false;
        }
        boolean f1 = flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right);
        boolean f2 = flipEquiv(root1.right, root2.left) && flipEquiv(root1.left, root2.right);
        return f1 || f2;
    }
}
